package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.domain.TreeSelect;
import com.rabbit.eap.system.dto.SysDeptDTO;
import com.rabbit.eap.system.entity.SysDept;
import com.rabbit.eap.system.param.SysDeptPageParam;
import com.rabbit.eap.system.service.ISysDeptService;
import com.rabbit.eap.system.vo.SysDeptVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysDeptController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 部门表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysDept")
@Module("system")
@Api(value = "部门表API", tags = {"部门表"})
public class SysDeptController extends BaseController {

    @Autowired
    private ISysDeptService sysDeptService;


    /**
    * @Description: 添加部门表
    * @methodName: saveSysDept
    * @param sysDeptDTO:sysDeptDTO数据传输对象
    * @return: ApiResult.result(flag)
    * @date: 2020/06/06 23:05:26
    * @author: rabbit
    */
    @PostMapping("/saveSysDept")
    @RequiresPermissions("sys:dept:add")
    @OperationLog(name = "添加部门表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加部门表", response = ApiResult.class)
    public ApiResult saveSysDept(@Validated(AddGroup.class) @RequestBody SysDeptDTO sysDeptDTO) throws Exception {
        ApiResult apiResult = sysDeptService.saveSysDept(sysDeptDTO);
        return apiResult;
    }
    /**
     * @Description: 修改部门表
     * @methodName: modifySysDept
     * @param  sysDeptDTO:sysDeptDTO数据传输对象
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysDept")
    @RequiresPermissions("sys:dept:edit")
    @OperationLog(name = "修改部门表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改部门表", response = ApiResult.class)
    public ApiResult modifySysDept(@Validated(UpdateGroup.class) @RequestBody SysDeptDTO sysDeptDTO) throws Exception {
        ApiResult  apiResult = sysDeptService.modifySysDept(sysDeptDTO);
        return apiResult;
    }
    /**
     * @Description: 删除部门表
     * @methodName: removeSysDept
     * @param deptId:部门Id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysDept/{deptId}")
    @RequiresPermissions("sys:dept:remove")
    @OperationLog(name = "删除部门表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除部门表", response = ApiResult.class)
    public ApiResult  removeSysDept(@PathVariable("deptId") Long deptId) throws Exception {
        ApiResult  apiResult = sysDeptService.removeSysDept(deptId);
        return apiResult;
    }

    /**
     * @Description: 根据Id获取部门表详情
     * @methodName: getSysDeptInfo
     * @param id: id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysDeptInfo")
    @RequiresPermissions("sys:dept:query")
    @OperationLog(name = "部门表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "部门表详情", response = ApiResult.class)
    public ApiResult getSysDeptInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysDeptService.getSysDeptById(id);
        return apiResult;
    }

    /**
     * @Description: 部门表分页列表
     * @methodName: getSysDeptPageList
     * @param sysDeptPageParam
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysDeptPageList")
    @RequiresPermissions("sys:dept:list")
    @OperationLog(name = "部门表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "部门表分页列表", response = ApiResult.class)
    public ApiResult getSysDeptPageList(@Validated @RequestBody SysDeptPageParam sysDeptPageParam) throws Exception {
        ApiResult  apiResult = sysDeptService.getSysDeptPageList(sysDeptPageParam);
        return apiResult;
    }
    /**
     * @Description: 获取部门列表
     * @methodName: getSysDeptList
     * @param sysDeptPageParam:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/26 20:18
     * @author: rabbit
     *
     */
    @GetMapping("/getSysDeptList")
    @OperationLog(name = "部门列表", type = OperationLogType.LIST)
    @ApiOperation(value = "部门列表", response = ApiResult.class)
    public ApiResult getSysDeptList(SysDeptPageParam sysDeptPageParam){
        List<SysDept> list =sysDeptService.getSysDeptList(sysDeptPageParam);
        return ApiResult.ok(list);
    }/**
     * @Description: 获取部门列表
     * @methodName: getSysDeptList
     * @param sysDeptPageParam:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/26 20:18
     * @author: rabbit
     *
     */
    @GetMapping("/getSysDeptAll")
    @OperationLog(name = "部门列表", type = OperationLogType.LIST)
    @ApiOperation(value = "部门列表", response = ApiResult.class)
    public ApiResult getSysDepAll(@Validated SysDeptPageParam sysDeptPageParam){
        List<SysDeptVO> list =sysDeptService.getSysDeptAll(sysDeptPageParam);
        return ApiResult.ok(list);
    }
    /**
     * @Description: 获取部门下拉列列表
     * @methodName: getDeptTree
     * @param :
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/26 20:56
     * @author: rabbit
     *
     */
    @GetMapping("/getDeptTree")
    @OperationLog(name = "获取部门下拉列列表", type = OperationLogType.LIST)
    @ApiOperation(value = "获取部门下拉列列表", response = ApiResult.class)
    public ApiResult getDeptTree(@Validated SysDeptPageParam sysDeptPageParam){
        List<TreeSelect> list = sysDeptService.getDeptTree(sysDeptPageParam);
        return ApiResult.ok(list);
    }

    /**
     * @Description: 获取对应角色部门列表树
     * @methodName: getRoleDeptTree
     * @param roleId: 角色id
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/26 21:37
     * @author: rabbit
     *
     */
    @GetMapping("/getRoleDeptTree/{roleId}")
    @OperationLog(name = "加载对应角色部门列表树", type = OperationLogType.LIST)
    @ApiOperation(value = "加载对应角色部门列表树", response = ApiResult.class)
    public ApiResult getRoleDeptTree(@PathVariable("roleId") Long roleId){
        ApiResult apiResult = sysDeptService.getRoleDeptTree(roleId);
        return apiResult;
    }

    @GetMapping("/getRoleDept/{roleId}")
    @OperationLog(name = "加载对应角色部门列表树", type = OperationLogType.LIST)
    @ApiOperation(value = "加载对应角色部门列表树", response = ApiResult.class)
    public ApiResult getRoleDept(@PathVariable("roleId") Long roleId){
        ApiResult apiResult  = sysDeptService.getRoleDept(roleId);
        return  apiResult;
    }

}

